<?php

/**
 * 更新数据结构
 **/

$prefix = \Phpcmf\Service::M()->prefix;

$table = $prefix . 'weixin_content';

// 创建字段 代码
if (!\Phpcmf\Service::M()->db->fieldExists('nums', $table)) {
    \Phpcmf\Service::M()->query('ALTER TABLE `' . $table . '` ADD `nums` tinyint(2) DEFAULT  \'0\'');
}
if (!\Phpcmf\Service::M()->db->fieldExists('status', $table)) {
    \Phpcmf\Service::M()->query('ALTER TABLE `' . $table . '` ADD `status` tinyint(2) DEFAULT  \'0\'');
}
if (!\Phpcmf\Service::M()->db->fieldExists('publish_id', $table)) {
    \Phpcmf\Service::M()->query('ALTER TABLE `' . $table . '` ADD `publish_id` varchar(255) DEFAULT  \'\'');
}
if (!\Phpcmf\Service::M()->db->fieldExists('article_id', $table)) {
    \Phpcmf\Service::M()->query('ALTER TABLE `' . $table . '` ADD `article_id` varchar(255) DEFAULT  \'\'');
}

//新增设置
$shezhibiao = $prefix.'app_weixin_shezhi_tongzhi';
if (!\Phpcmf\Service::M()->db->tableExists($shezhibiao)) {
    \Phpcmf\Service::M()->query("CREATE TABLE IF NOT EXISTS `".$shezhibiao."` (
    `id` smallint(5) UNSIGNED NOT NULL,
    `site` mediumtext COLLATE utf8mb4_unicode_ci COMMENT '站点划分',
    `dirname` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '目录名称',
    `share` tinyint(1) UNSIGNED DEFAULT NULL COMMENT '是否共享模块',
    `setting` text COLLATE utf8mb4_unicode_ci COMMENT '配置信息',
    `comment` text COLLATE utf8mb4_unicode_ci COMMENT '评论信息',
    `disabled` tinyint(1) NOT NULL DEFAULT '0' COMMENT '禁用？',
    `displayorder` smallint(5) DEFAULT '0',
	PRIMARY KEY (`id`),
	KEY `dirname` (`dirname`),
	KEY `disabled` (`disabled`),
	KEY `displayorder` (`displayorder`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='微信通知模块表';");
}
$biaoming='weixin';
$shezhibiaoshuju = \Phpcmf\Service::M('Module')->table($shezhibiao)->where('id', 1)->getRow();
if (!$shezhibiaoshuju) {
\Phpcmf\Service::M()->query_sql('
INSERT INTO `'.$shezhibiao.'` (`id`, `site`, `dirname`, `share`, `setting`, `comment`, `disabled`, `displayorder`) VALUES
(1,\'{\"1\":{\"html\":0,\"theme\":\"default\",\"domain\":\"\",\"template\":\"default\"}}\',\''.$biaoming.'\',0,\'{\"pages\":{\"quan_shoucheng\":\"0.9\",\"quan_shouru\":\"1\"}}\',NULL,0,0)
');
}
